<%--
  Created by IntelliJ IDEA.
  User: 王辉
  Date: 2022/5/9
  Time: 23:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.*" %>
<% request.setCharacterEncoding("UTF-8");%>
<html>
<head>
    <title>登陆验证中</title>
</head>
<body>
<%
    String driverName="com.mysql.cj.jdbc.Driver";
    String username = "root";
    String password = "123456";
    String url = "jdbc:mysql://localhost:3306/t_card?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false";
    Class.forName(driverName);
    Connection conn = DriverManager.getConnection(url,username,password);
    String loginUserName = request.getParameter("username");
    String loginPassword = request.getParameter("password");
    String sql = "SELECT password FROM user WHERE username = ? ";
    PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setString(1,loginUserName);
    ResultSet rs = pstmt.executeQuery();
    String selectPassword = "";
    while(rs.next()){
        selectPassword = rs.getString("password");
    }
    if(selectPassword.equals(loginPassword)){
        session.setAttribute("username",loginUserName);
        response.sendRedirect("index.jsp");
    }else {
        %>
        <div align="center"><br><br><br>
            <h1>账号或密码错误</h1>
            <a href="login.jsp" style="color: cadetblue">重新登录</a>  &nbsp;&nbsp;&nbsp;
            <a href="register.jsp" style="color: red">还没有账号，这就去注册</a> &nbsp;&nbsp;&nbsp;
            <a href="retrieve.jsp" style="color: cyan">找回密码</a>
        </div>
<%
    }

%>
</body>
</html>
